{extend name="index_layout"/}
{block name="main"}
<style>
    .layui-upload-img {
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
    }
</style>
<div class="layui-card">
    <div class="layui-card-header">添加文章</div>
    <div class="layui-card-body">
        <form class="layui-form form-horizontal" action="{:url('admin/helpArticle/edit')}" method="post">
            <input type="hidden" name="id" value="{$data.id}" />
            <div class="layui-form-item">
                <label class="layui-form-label">文章标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" value="{$data.title}" autocomplete="off" placeholder="文章标题" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章简介</label>
                <div class="layui-input-inline">
                    <textarea type="text" name="text"  autocomplete="off" placeholder="文章简介" class="layui-input">{$data.text}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文章类别</label>
                <div class="layui-input-inline">
                    <select name="type">
                        <option value="2" {if $data.type==2}selected{/if}>公告</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否置顶</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="isTop" id="isTop" lay-skin="switch" lay-text="是|否" lay-filter="isIndex" {if $data.isTop==1}checked{/if}>
                </div>
            </div>
            <div class="layui-form-item" style="margin-left: 53px;margin-top: 20px;">
                <label class="layui-form-labe">缩略图</label>
                <div class="layui-upload">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1" src="{$data.pic}">
                        <p id="demoText"></p>
                    </div>
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                </div>
            </div>
            <input type="hidden" id="pic" name="pic">
            <!--<div class="layui-form-item" style="margin-left: 53px;margin-top: 20px;">-->
                <!--<label class="layui-form-labe">文章内容</label>-->
                <!--<textarea id="demo" name="info" lay-verify="content"  style="display: none;">{$data.info}</textarea>-->
            <!--</div>-->
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-labe">文章内容</label>
                <div class="layui-form-field-label">
                    <script type="text/javascript" src="__STATIC__/libs/ueditor/ueditor.config.js"></script>
                    <script type="text/javascript" src="__STATIC__/libs/ueditor/ueditor.all.js"></script>
                    <script type="text/javascript">
                        var info = UE.getEditor('info',{
                            initialFrameWidth: null,
                            initialFrameHeight: 250,
                            serverUrl: "{:url('attachment/Ueditor/run')}"
                        });

                    </script>
                    <script type="text/plain" id="info" name="info">{$data.info|raw}</script>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn ajax-post" lay-submit="" lay-filter="*" target-form="form-horizontal">立即提交</button>
                </div>
            </div>
        </form>
        <div class="layui-form-item" style="margin-left: 100px;margin-top: -52px;">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" onClick="javascript :history.back(-1);">返回</button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/admin/js/common.js"></script>
<script type="text/javascript">
    layui.use(['layer','layedit','upload','form'], function() {
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var upload = layui.upload;
        var layedit = layui.layedit;
        var index = layedit.build('demo'); //建立编辑器

        //自定义验证规则
        form.verify({
            content: function (value) {
                return layedit.sync(index);
            }
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: 'uploads'
            ,data:{'type':'article'}
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                console.log(res);
                if(res.info == 1){
                    $('#pic').val(res.savename);
                }else{
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


    });
</script>
{/block}